import { Model, DataTypes, Optional } from 'sequelize';
import sequelize from './index';

export interface DoudizhuAttributes {
  uid: number;
  win: number;
  lose: number;
  escape: number;
  gold: number;
}

interface DoudizhuCreationAttributes extends Optional<DoudizhuAttributes, 'uid'> { }

class Doudizhu extends Model<DoudizhuAttributes, DoudizhuCreationAttributes>
  implements DoudizhuAttributes {
  public uid!: number;
  public win!: number;
  public lose!: number;
  public escape!: number;
  public gold!: number;
}

Doudizhu.init(
  {
    uid: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      allowNull: false,
      unique: true,
      comment: '用户Id'
    },
    win: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '赢'
    },
    lose: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '输'
    },
    escape: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '逃跑'
    },
    gold: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1000,
      comment: '金币'
    }
  },
  {
    sequelize,
    modelName: 'Doudizhu',
    tableName: 'doudizhu',
    timestamps: false,
    paranoid: false,
    indexes: [{ unique: false, name: 'uid', fields: ['uid'] }],
    comment: '用户斗地主数据表'
  }
)

export default Doudizhu
